package com.zygh.policeasset.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.util.StringUtil;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.Basics;
import com.zygh.policeasset.pojo.StartProvisionDate;
import com.zygh.policeasset.service.AssetOverhaulService;
import com.zygh.policeasset.service.AssetTransferService;
import com.zygh.policeasset.service.BasicsService;
import com.zygh.policeasset.service.DailyAssetsService;
import com.zygh.policeasset.service.HardwitService;
import com.zygh.policeasset.service.PurchaseService;
import com.zygh.policeasset.service.SettlementService;
import com.zygh.policeasset.service.SoftwitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/basics"})
@Api(tags = {"基础资产"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/BasicsController.class */
public class BasicsController {
    @Autowired
    HardwitService hardwitService;
    @Autowired
    BasicsService basicsService;
    @Autowired
    SoftwitService softwitService;
    @Autowired
    AssetTransferService assetTransferService;
    @Autowired
    AssetOverhaulService assetOverhaulService;
    @Autowired
    DailyAssetsService dailyAssetsService;
    @Autowired
    PurchaseService purchaseService;
    @Autowired
    SettlementService settlementService;

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加基础资产")
    public Object add(@RequestBody Basics basics) {
        if (StringUtil.isEmpty(basics.getBuildNum())) {
            return new CommonResult().validateFailed("项目编号不能为空");
        }
        if (this.basicsService.insert(basics) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    @RequestMapping(value = {"/delete"}, method = {RequestMethod.GET})
    @ApiOperation("删除基础资产")
    public Object delete(@RequestParam Integer id) {
        if (StringUtil.isEmpty(String.valueOf(id))) {
            return new CommonResult().validateFailed("基础资产主键不能为空");
        }
        if (this.basicsService.deleteById(id.intValue()) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("修改基础资产")
    public Object update(@RequestBody Basics basics) {
        if (StringUtil.isEmpty(String.valueOf(basics.getId()))) {
            return new CommonResult().validateFailed("基础资产主键不能为空");
        }
        if (this.basicsService.updateById(basics) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    @RequestMapping(value = {"/selectbyid"}, method = {RequestMethod.GET})
    @ApiOperation("单条基础资产查询")
    public Object selectById(@RequestParam Integer id) {
        if (StringUtil.isEmpty(String.valueOf(id))) {
            return new CommonResult().validateFailed("基础资产主键不能为空");
        }
        return new CommonResult().success(this.basicsService.findById(id));
    }

    @RequestMapping(value = {"/findall"}, method = {RequestMethod.GET})
    @ApiOperation("查询全部基础资产")
    public Object findAll(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize) {
        return this.basicsService.findAll(pageNum, pageSize);
    }

    @RequestMapping(value = {"/findbycondition"}, method = {RequestMethod.GET})
    @ApiOperation("按项目编号查询")
    public Object findByCondition(@RequestParam String buildNum, @RequestParam String assetsStatus, @RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize) {
        if (StringUtil.isEmpty(buildNum)) {
            return new CommonResult().validateFailed("项目编号不能为空");
        }
        return this.basicsService.findByCondition(buildNum, pageNum, pageSize);
    }

    @RequestMapping(value = {"/findByroleid"}, method = {RequestMethod.GET})
    @ApiOperation("按角色、编号、资产状态查询")
    public Object findByRoleId(Basics basics, @RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize) {
        return this.basicsService.findByRoleId(basics, pageNum, pageSize);
    }

    @RequestMapping(value = {"/findbytransfer"}, method = {RequestMethod.GET})
    @ApiOperation("基础资产转移查询")
    public Object findBytransfer(Basics basics, @RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize) {
        if (basics.getAssetsStatus().equals("jc2")) {
            return this.basicsService.findByoverhaul(basics, pageNum, pageSize);
        }
        if (basics.getAssetsStatus().equals("jc3")) {
            return this.basicsService.findBytransfer(basics, pageNum, pageSize);
        }
        return this.basicsService.findByRoleId(basics, pageNum, pageSize);
    }

    @RequestMapping(value = {"/findbyidandtype"}, method = {RequestMethod.GET})
    @ApiOperation("资产转移、大修流程查询")
    public Object findByIdAndType(@RequestParam Integer assetId, @RequestParam String assetType) {
        if (assetType.equals("jc2") || assetType.equals("znh2")) {
            return this.assetOverhaulService.findByIdAndType(assetId, assetType);
        }
        return this.assetTransferService.findByIdAndType(assetId, assetType);
    }

    @RequestMapping(value = {"/updatestopruntime"}, method = {RequestMethod.GET})
    @ApiOperation("修改基础资产")
    public Object updateStopRunTime(@RequestParam String stopRunTime, @RequestParam String whetherEnable, @RequestParam Integer id, @RequestParam String type) {
        int count;
        if (StringUtil.isEmpty(String.valueOf(id))) {
            return new CommonResult().validateFailed("基础资产主键不能为空");
        }
        if ("jc2".equals(type)) {
            count = this.basicsService.updateStopRunTime(stopRunTime, whetherEnable, id);
        } else {
            count = this.hardwitService.updateStopRunTime(stopRunTime, whetherEnable, id);
        }
        if (count > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    @RequestMapping(value = {"/updateStartProvisionDate"}, method = {RequestMethod.POST})
    @ApiImplicitParams({@ApiImplicitParam(name = "startProvisionDate", value = "日期", required = true, paramType = "query"), @ApiImplicitParam(name = "buildNum", value = "项目编号", required = true, paramType = "query"), @ApiImplicitParam(name = "sectionId", value = "标段ID", required = true, paramType = "query"), @ApiImplicitParam(name = "type", value = "jc或zn", required = true, paramType = "query")})
    @ApiOperation("修改开始计提折旧日期(基础和智能)")
    public Object updateStartProvisionDate(@RequestBody List<StartProvisionDate> jsonArray) {
        Integer count = 0;
        for (StartProvisionDate startProvisionDate1 : jsonArray) {
            String startProvisionDate = startProvisionDate1.getStartProvisionDate();
            String buildNum = startProvisionDate1.getBuildNum();
            Integer sectionId = startProvisionDate1.getSectionId();
            String type = startProvisionDate1.getType();
            if ("jc".equals(type)) {
                if (this.basicsService.findCountByNumAndId(buildNum, sectionId).intValue() <= 0) {
                    return new CommonResult().validateFailed("当前项目无资产，请录入资产");
                }
                if (Integer.valueOf(this.settlementService.updateSPD(startProvisionDate, null, buildNum, sectionId)).intValue() == 0) {
                    return new CommonResult().validateFailed("修改审计结算失败");
                }
                count = this.basicsService.updateStartProvisionDate(startProvisionDate, buildNum, sectionId);
            } else if ("zn".equals(type)) {
                Integer a = this.hardwitService.findCountByNumAndId(buildNum, sectionId);
                Integer count1 = 0;
                if (a.intValue() > 0) {
                    if (Integer.valueOf(this.settlementService.updateSPD(startProvisionDate, null, buildNum, sectionId)).intValue() == 0) {
                        return new CommonResult().validateFailed("修改审计结算失败");
                    }
                    count1 = this.hardwitService.updateStartProvisionDate(startProvisionDate, buildNum, sectionId);
                }
                Integer b = this.softwitService.findCountByNumAndId(buildNum, sectionId);
                Integer count2 = 0;
                if (b.intValue() > 0) {
                    if (Integer.valueOf(this.settlementService.updateSPD(startProvisionDate, null, buildNum, sectionId)).intValue() == 0) {
                        return new CommonResult().validateFailed("修改审计结算失败");
                    }
                    count2 = this.softwitService.updateStartProvisionDate(startProvisionDate, buildNum, sectionId);
                }
                if (a.intValue() + b.intValue() == 0) {
                    return new CommonResult().validateFailed("当前项目无资产，请录入资产");
                }
                count = Integer.valueOf(count1.intValue() + count2.intValue());
            } else {
                continue;
            }
        }
        if (count.intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    @RequestMapping(value = {"/updassetsClassificationId"}, method = {RequestMethod.POST})
    @ApiImplicitParams({@ApiImplicitParam(name = "ids", value = "资产主键集合，逗号隔开", required = true, paramType = "query"), @ApiImplicitParam(name = "assetsClassificationId", value = "资产新分类Id", required = true, paramType = "query"), @ApiImplicitParam(name = "assetsClassificationPid", value = "资产新分类父Id", required = true, paramType = "query"), @ApiImplicitParam(name = "type", value = "jc(基础)、znh(智能硬件)、zns(智能软件)、da(日常资产)、pu(采购资产)", required = true, paramType = "query")})
    @ApiOperation("修改资产分类编号jc(基础)、znh(智能硬件)、zns(智能软件)、da(日常资产)、pu(采购资产)")
    public Object updassetsClassificationId(@RequestBody JSONObject json) {
        String ids = json.getString("ids");
        Integer assetsClassificationId = json.getInteger("assetsClassificationId");
        Integer assetsClassificationPid = json.getInteger("assetsClassificationPid");
        String type = json.getString("type");
        Integer count = 0;
        if ("jc".equals(type)) {
            count = this.basicsService.updassetsClassificationId(ids, assetsClassificationId, assetsClassificationPid);
        } else if ("znh".equals(type)) {
            count = this.hardwitService.updassetsClassificationId(ids, assetsClassificationId, assetsClassificationPid);
        } else if ("zns".equals(type)) {
            count = this.softwitService.updassetsClassificationId(ids, assetsClassificationId, assetsClassificationPid);
        } else if ("da".equals(type)) {
            count = this.dailyAssetsService.updassetsClassificationId(ids, assetsClassificationId, assetsClassificationPid);
        } else if ("pu".equals(type)) {
            count = this.purchaseService.updassetsClassificationId(ids, assetsClassificationId, assetsClassificationPid);
        }
        if (count.intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }
}